import cv2
import numpy as np

edge_img = cv2.imread('edges_img.jpg', cv2.IMREAD_GRAYSCALE)

# 创建一个与给定数组形状和类型相同的新数组，所有元素都初始化为 0
mask = np.zeros_like(edge_img)
mask = cv2.fillPoly(mask,
                    np.array([[[0, 368], [300, 210], [340, 210], [640, 368]]]),
                    color=255)

masked_edge_img = cv2.bitwise_and(edge_img, mask)
cv2.imwrite('masked_edge_img.jpg', masked_edge_img)
cv2.imshow('masked', masked_edge_img)
cv2.waitKey(0)


